CHARTS

Ranking Bar Plots

Ordering Bars in ggplot2

Bar charts are very helpful for displaying the frequencies of different categories of data. Sometimes, it can be useful to order and rank the bar plots in a way it matches with the story we’re telling. By default, while creating a bar plot with categorical labels, ggplot will order the plot alphabetically. In that case, there are a few ways to rank the the bar plot:

  • Using factor() levels : By converting data into a factor, we can order bars manually using the levels
  • Using factor() : We can order bars in numerically ascending/descending order using factor() appropriately
  • Using reorder() : We can also utilize the reorder() function to rank bars numerically. For Descending order, we use reorder(x,y). For Ascending order, we use reorder(x,-y).

Bar Charts can be ranked whether it is in a horizontal format or a vertical format.